import 'package:flutter/material.dart';
import 'package:flutter_base_library/index.dart';
import 'package:get/get.dart';
import 'package:safe_manage/models/index.dart';
import 'package:safe_manage/widgets/event_status_tag.dart';
import 'package:safe_manage/widgets/list_cell_info_item.dart';
import 'alarm_type_list_item_controller.dart';

class AlarmTypeListItemWidget extends GetView<AlarmTypeListItemController> {
  final CommonRecord commonRecord;
  final int type;
  const AlarmTypeListItemWidget(this.commonRecord, this.type, {super.key});
  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: AlarmTypeListItemController(),
      global: false,
      builder: (_) {
        return Container(
          margin: const EdgeInsets.fromLTRB(15, 0, 15, 0),
          padding: const EdgeInsets.fromLTRB(13, 15, 13, 10),
          width: Get.width,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Expanded(
                    child: Text(
                      commonRecord.rwmc ?? "",
                      style: const TextStyle(
                        color: Color(0xff101010),
                        fontSize: 18,
                      ),
                    ),
                  ),
                  Visibility(
                    visible: type != 5 && type != 4,
                    child: EventStatusTag(
                      status: commonRecord.sfcl,
                    ),
                  ),
                  Visibility(
                    visible: type == 4 &&
                        commonRecord.wcbz == 1 &&
                        commonRecord.sbjg == 2,
                    child: EventStatusTag(
                      status: commonRecord.sfcl,
                    ),
                  ),
                ],
              ),
              const SizedBox(height: 7),
              _infoWidget(),
              const SizedBox(height: 10),
              const Divider(
                color: Color(0xFFEFEFF4),
                height: 1,
              ),
              const SizedBox(height: 10),
              Container(
                alignment: Alignment.centerRight,
                child: ListCellInfoItem(
                  () {
                    int? milliseSecond = commonRecord.cjsj?.toInt();
                    if (milliseSecond != null) {
                      DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
                        milliseSecond * 1000,
                      );
                      return toLocalDateTimeByDateTime(dateTime);
                    }
                    return "----/--/-- --:--:--";
                  }(),
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  Widget _infoWidget() {
    switch (type) {
      case 0:
        return _infoContent0();
      case 1:
        return _infoContent1();
      case 2:
        return _infoContent2();
      case 3:
        return _infoContent3();
      case 4:
        return _infoContent4();
      case 5:
        return _infoContent5();
      case 6:
        return _infoContent6();
      default:
        return Container();
    }
  }

  // 抽烟检测
  Widget _infoContent0() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "报警状态：${() {
                  if (commonRecord.sbjg == 1) {
                    return "正常";
                  }
                  if (commonRecord.sbjg == 2) {
                    return "报警";
                  }
                  return "";
                }()}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "设备：${commonRecord.camera?.sbmc ?? ""}",
              ),
            ),
          ],
        ),
      ],
    );
  }

  // 电子围栏
  Widget _infoContent1() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "设备ip:${commonRecord.camera?.sbip}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "设备：${commonRecord.camera?.sbmc ?? ""}",
              ),
            ),
            // Expanded(
            //   child: ListCellInfoItem(
            //     "置信度：${commonRecord.score}",
            //   ),
            // ),
          ],
        ),
      ],
    );
  }

  // 电话检测
  Widget _infoContent2() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "报警状态：${() {
                  if (commonRecord.sbjg == 1) {
                    return "正常";
                  }
                  if (commonRecord.sbjg == 2) {
                    return "报警";
                  }
                  return "";
                }()}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "设备：${commonRecord.camera?.sbmc ?? ""}",
              ),
            ),
            // Expanded(
            //   child: ListCellInfoItem(
            //     "接打电话人数：${commonRecord.total}",
            //   ),
            // ),
          ],
        ),
      ],
    );
  }

  // 烟火识别
  Widget _infoContent3() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "报警状态：${() {
                  if (commonRecord.sbjg == 1) {
                    return "正常";
                  }
                  if (commonRecord.sbjg == 2) {
                    return "报警";
                  }
                  return "";
                }()}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "设备：${commonRecord.camera?.sbmc ?? ""}",
              ),
            ),
          ],
        ),
      ],
    );
  }

  // 装卸油
  Widget _infoContent4() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "报警状态：${() {
                  if (commonRecord.sbjg == 1) {
                    return "正常";
                  }
                  if (commonRecord.sbjg == 2) {
                    return "报警";
                  }
                  return "";
                }()}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "备注：${commonRecord.ms}",
              ),
            ),
          ],
        ),
      ],
    );
  }

  // 加油站巡检
  Widget _infoContent5() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "巡检总数：${commonRecord.xjzs ?? ""}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "上午总数：${commonRecord.swsl ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "下午总数：${commonRecord.xwsl ?? ""}",
              ),
            ),
          ],
        ),
      ],
    );
  }

  // 车顶作业
  Widget _infoContent6() {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "部门：${commonRecord.cjbmmc ?? ""}",
              ),
            ),
            Expanded(
              child: ListCellInfoItem(
                "报警状态：${() {
                  if (commonRecord.sbjg == 1) {
                    return "正常";
                  }
                  if (commonRecord.sbjg == 2) {
                    return "报警";
                  }
                  return "";
                }()}",
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        Row(
          children: [
            Expanded(
              child: ListCellInfoItem(
                "设备：${commonRecord.camera?.sbmc ?? ""}",
              ),
            ),
            // Expanded(
            //   child: ListCellInfoItem(
            //     "违规人数：${commonRecord.total}",
            //   ),
            // ),
          ],
        ),
      ],
    );
  }
}
